//
//  TicTacModel.h
//  TicTacToe
//
//  Created by Tim on 09-11-23.
//  Copyright 2009 Tim Dimsdale. All rights reserved.
//
// This file is part of TicTacToe.
// 
// TicTacToe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// TicTacToe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with TicTacToe.  If not, see <http://www.gnu.org/licenses/>
//
#import <Cocoa/Cocoa.h>

#define TICTAC_NOBODY 0
#define TICTAC_X 1
#define TICTAC_O 2


/*!
 \brief The data model for the tic tac game itself.
 */
@interface TicTacModel : NSObject {
	/*! The tic tac grid is just a simple two dimensional c array.
	 */
	int playingTable[3][3];
}

/*!
 \brief Gets the player code for the supplied x and y position
 \param x the grid x position (0-2)
 \param y the grid y position (0-2)
 \returns the player code for the position (TICTAC_NOBODY, TICTAC_X, or TICTAC_O )
 */
-(int) getPlayerAtX:(int)x andY:(int)y;

/*!
 \brief Sets the player code for the supplied x and y position
 \param x the grid x position (0-2)
 \param y the grid y position (0-2)
 \param  player code for the position (TICTAC_NOBODY, TICTAC_X, or TICTAC_O )
 \param error A return NSError in the event something bad happens (such as the position is not available)
 */-(void) setPlayerAtX:(int)x andY:(int)y withPlayer:(int)player error:(NSError**)error;

/*!
 \brief Helper method.  Asks is the other player (but not empty) is at the supplied position.
 \param x the grid x position (0-2)
 \param y the grid y position (0-2)
 \param playerCode the player code of the caller (TICTAC_NOBODY, TICTAC_X, or TICTAC_O )
 \returns Whether or not the other player is at the indicated position.
 */
-(bool) isOtherPlayerAtX:(int)x andY:(int)y andIAm:(int)playerCode;

/*!
 \brief Helper method.  Asks is the supplied position is available to use.
 \param x the grid x position (0-2)
 \param y the grid y position (0-2)
 \returns Whether or not the position is available.
 */
-(bool) isPositionAvailableAtX:(int)x andY:(int)y;
/*!
 \brief Gets the player code for the first winner detected in the model.
 \returns the player code of the winner, TICTAC_NOBODY if nobody won.
 */
-(int) getAnyWinner; 

/*!
 \brief Internal, do not use.
 */
-(void)debugDumpModel;
/*!
 \brief Clears the model, setting all positions to be TICTAC_NOBODY
 */
-(void)clear;

@end
